﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DSARC.Graph;

namespace YenAlgorithm
{
    public class YenAlgorithm
    {
        public Graph graph = new Graph();
        List<int> slist = new List<int>();
        List<int> dlist = new List<int>();
        List<double> wlist = new List<double>(2);
        List<Path> shortest_paths_list = new List<Path>();

        public YenAlgorithm(int nodenum, List <int> slist, List<int> dlist, List<double> wlist)
        {

            this.slist = slist;
            this.dlist = dlist;
            this.wlist = wlist;

            graph = new Graph(nodenum,slist, dlist, wlist);
            
        }

        public List<List<double>> getKShortestPaths(int source, int dest, int k)
        {
            YenTopKShortestPathsAlg yenAlg = new YenTopKShortestPathsAlg(graph);
            shortest_paths_list = yenAlg.get_shortest_paths(
                graph.get_vertex(source), graph.get_vertex(dest), k);
            
            List<List<double>> tmp = new List<List<double>>();
            foreach (var path in shortest_paths_list)
            {
                List<double> vertmp = new List<double>();
                foreach (var ver in path.get_vertices())
                {
                    vertmp.Add(ver.get_id());
                }
                vertmp.Add(path.get_weight());
                tmp.Add(vertmp);
            }

            return tmp;
        }
    }
}
